<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>NeonBank - Dashboard</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
    <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="{{ url_for('static', filename='css/style.css') }}" rel="stylesheet">
    <link rel="icon" href="{{ url_for('static', filename='favicon.ico') }}">
</head>
<body>
    <nav class="navbar navbar-expand-lg navbar-dark">
        <div class="container-fluid">
            <a class="navbar-brand" href="#"><i class="fas fa-bank me-2"></i>NeonBank</a>
            <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav">
                <span class="navbar-toggler-icon"></span>
            </button>
            <div class="collapse navbar-collapse" id="navbarNav">
                <ul class="navbar-nav ms-auto">
                    <li class="nav-item"><a class="nav-link" href="#" data-bs-toggle="modal" data-bs-target="#createModal"><i class="fas fa-user-plus me-2"></i>Create Account</a></li>
                    <li class="nav-item"><a class="nav-link" href="#" data-bs-toggle="modal" data-bs-target="#depositModal"><i class="fas fa-money-bill-wave me-2"></i>Deposit</a></li>
                    <li class="nav-item"><a class="nav-link" href="#" data-bs-toggle="modal" data-bs-target="#withdrawModal"><i class="fas fa-money-check-alt me-2"></i>Withdraw</a></li>
                    <li class="nav-item"><a class="nav-link" href="#" data-bs-toggle="modal" data-bs-target="#transferModal"><i class="fas fa-exchange-alt me-2"></i>Transfer</a></li>
                </ul>
            </div>
        </div>
    </nav>

    <div class="container mt-4">
        <h1 class="text-center mb-4"><i class="fas fa-wallet me-2"></i>Account Dashboard</h1>

        <div id="alert-container" class="mb-4"></div>

        {% with messages = get_flashed_messages(with_categories=true) %}
            {% if messages %}
                {% for category, message in messages %}
                    <div class="alert alert-{{ 'success' if category == 'success' else 'danger' }} alert-dismissible fade show" role="alert">
                        {{ message }}
                        <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
                    </div>
                {% endfor %}
            {% endif %}
        {% endwith %}

        <div class="row" id="account-list"></div>

        <div class="text-center mt-4">
            <button class="btn btn-primary" id="simulate-btn"><i class="fas fa-sync-alt me-2"></i>Run Concurrent Simulation</button>
            <div id="simulate-progress" class="progress mt-3 d-none" style="max-width: 300px; margin: auto;">
                <div class="progress-bar bg-primary" role="progressbar" style="width: 0%"></div>
            </div>
        </div>

        <!-- Add account selector for chart -->
        <div class="mt-4">
            <label for="chart-account-selector" class="form-label">Select Account for Balance History</label>
            <select class="form-control" id="chart-account-selector" style="max-width: 300px; margin: auto;">
                <option value="">Select an account</option>
                <!-- Populated via JS -->
            </select>
        </div>

        <canvas id="balanceChart" class="mt-4"></canvas>
        <div id="no-data-message" class="text-center mt-2 d-none">No transaction history available for this account.</div>
    </div>

    <!-- Modals (unchanged from previous, included for completeness) -->
    <div class="modal fade" id="createModal" tabindex="-1" aria-labelledby="createModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title" id="createModalLabel"><i class="fas fa-user-plus me-2"></i>Create Account</h5>
                    <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                </div>
                <div class="modal-body">
                    <form id="create-form">
                        <div class="mb-3">
                            <label for="name" class="form-label">Name</label>
                            <input type="text" class="form-control" id="name" name="name" required aria-describedby="nameHelp">
                            <div id="nameHelp" class="form-text">Enter account holder's name.</div>
                        </div>
                        <div class="mb-3">
                            <label for="initial_balance" class="form-label">Initial Balance</label>
                            <input type="number" step="0.01" class="form-control" id="initial_balance" name="initial_balance" value="0.00" aria-describedby="balanceHelp">
                            <div id="balanceHelp" class="form-text">Optional initial deposit.</div>
                        </div>
                        <button type="submit" class="btn btn-primary w-100">Create</button>
                    </form>
                </div>
            </div>
        </div>
    </div>

    <div class="modal fade" id="depositModal" tabindex="-1" aria-labelledby="depositModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title" id="depositModalLabel"><i class="fas fa-money-bill-wave me-2"></i>Deposit</h5>
                    <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                </div>
                <div class="modal-body">
                    <form id="deposit-form">
                        <div class="mb-3">
                            <label for="deposit-account" class="form-label">Account</label>
                            <select class="form-control" id="deposit-account" name="account_id" required aria-describedby="accountHelp">
                                <!-- Populated via JS -->
                            </select>
                            <div id="accountHelp" class="form-text">Select account to deposit into.</div>
                        </div>
                        <div class="mb-3">
                            <label for="deposit-amount" class="form-label">Amount</label>
                            <input type="number" step="0.01" class="form-control" id="deposit-amount" name="amount" required aria-describedby="amountHelp">
                            <div id="amountHelp" class="form-text">Enter deposit amount.</div>
                        </div>
                        <button type="submit" class="btn btn-primary w-100">Deposit</button>
                    </form>
                </div>
            </div>
        </div>
    </div>

    <div class="modal fade" id="withdrawModal" tabindex="-1" aria-labelledby="withdrawModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title" id="withdrawModalLabel"><i class="fas fa-money-check-alt me-2"></i>Withdraw</h5>
                    <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                </div>
                <div class="modal-body">
                    <form id="withdraw-form">
                        <div class="mb-3">
                            <label for="withdraw-account" class="form-label">Account</label>
                            <select class="form-control" id="withdraw-account" name="account_id" required aria-describedby="accountHelp">
                                <!-- Populated via JS -->
                            </select>
                            <div id="accountHelp" class="form-text">Select account to withdraw from.</div>
                        </div>
                        <div class="mb-3">
                            <label for="withdraw-amount" class="form-label">Amount</label>
                            <input type="number" step="0.01" class="form-control" id="withdraw-amount" name="amount" required aria-describedby="amountHelp">
                            <div id="amountHelp" class="form-text">Enter withdrawal amount.</div>
                        </div>
                        <button type="submit" class="btn btn-primary w-100">Withdraw</button>
                    </form>
                </div>
            </div>
        </div>
    </div>

    <div class="modal fade" id="transferModal" tabindex="-1" aria-labelledby="transferModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title" id="transferModalLabel"><i class="fas fa-exchange-alt me-2"></i>Transfer</h5>
                    <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                </div>
                <div class="modal-body">
                    <form id="transfer-form">
                        <div class="mb-3">
                            <label for="from-account" class="form-label">From Account</label>
                            <select class="form-control" id="from-account" name="from_account_id" required aria-describedby="fromHelp">
                                <!-- Populated via JS -->
                            </select>
                            <div id="fromHelp" class="form-text">Select source account.</div>
                        </div>
                        <div class="mb-3">
                            <label for="to-account" class="form-label">To Account</label>
                            <select class="form-control" id="to-account" name="to_account_id" required aria-describedby="toHelp">
                                <!-- Populated via JS -->
                            </select>
                            <div id="toHelp" class="form-text">Select destination account.</div>
                        </div>
                        <div class="mb-3">
                            <label for="transfer-amount" class="form-label">Amount</label>
                            <input type="number" step="0.01" class="form-control" id="transfer-amount" name="amount" required aria-describedby="amountHelp">
                            <div id="amountHelp" class="form-text">Enter transfer amount.</div>
                        </div>
                        <button type="submit" class="btn btn-primary w-100">Transfer</button>
                    </form>
                </div>
            </div>
        </div>
    </div>

    <div class="modal fade" id="simulationModal" tabindex="-1" aria-labelledby="simulationModalLabel" aria-hidden="true">
        <div class="modal-dialog modal-lg">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title" id="simulationModalLabel"><i class="fas fa-sync-alt me-2"></i>Simulation Results</h5>
                    <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                </div>
                <div class="modal-body">
                    <ul class="list-group" id="simulation-log"></ul>
                </div>
            </div>
        </div>
    </div>

    <div class="modal fade" id="loadingModal" tabindex="-1" aria-labelledby="loadingModalLabel" aria-hidden="true">
        <div class="modal-dialog modal-dialog-centered">
            <div class="modal-content">
                <div class="modal-body text-center">
                    <div class="spinner-border text-primary" role="status">
                        <span class="visually-hidden">Loading...</span>
                    </div>
                    <p class="mt-2">Processing...</p>
                </div>
            </div>
        </div>
    </div>

    <footer class="footer mt-5">
        <p>&copy; 2025 NeonBank. All transactions are secure and encrypted. For help, contact support@govbank.example.</p>
    </footer>

    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
    <script src="{{ url_for('static', filename='js/script.js') }}"></script>
</body>
</html>